<?php


namespace api\controller;


use common\controller\VerifyController;
use common\service\DocumentRelationService;
use think\Request;

class DocumentRelationController extends VerifyController
{


    /**
     * @var DocumentRelationService
     */
    private $documentRelationService;

    public function __construct()
    {
        parent::__construct();
        $this->documentRelationService = DocumentRelationService::getInstance();
    }

    /**
     * 创建文档
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function createDocument(Request $request)
    {
        $res = $this->documentRelationService->createDocument($request->param(), $request->getTenantId());
        return json(success_response("OK", $res));
    }

    /**
     * 创建项目规范系统文档
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function createProjectSpecificationSystemDocument(Request $request)
    {
        $res = $this->documentRelationService->createProjectSpecificationSystemDocument($request->param(), $request->getTenantId());
        return json(success_response("OK", $res));
    }


    /**
     * 查询文档
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function findDocument(Request $request)
    {
        $res = $this->documentRelationService->findDocument($request->param());
        return json(success_response("OK", $res));
    }

    /**
     * 更新文档
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function updateDocument(Request $request)
    {
        $res = $this->documentRelationService->updateDocument($request->param());
        return json(success_response("OK", $res));
    }

    /**
     * 删除文档
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function deleteDocument(Request $request)
    {
        $res = $this->documentRelationService->deleteDocument($request->param());
        return json(success_response("OK", $res));
    }

    /**
     * 项目文档数据
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function selectDocuments(Request $request)
    {
        $res = $this->documentRelationService->selectDocuments($request->param(), $request->getTenantId());
        return json(success_response("OK", $res));
    }

    /**
     * 查询指定项目 指定目录下的文档
     * @param Request $request
     * @return \think\Response
     * @throws \Exception
     */
    public function selectCatalogDocuments(Request $request)
    {
        $res = $this->documentRelationService->selectCatalogDocuments($request->param(), $request->getTenantId());
        return json(success_response("OK", $res));
    }
}